<?php

namespace Payment\Common\Hsq\Data;

use Payment\Common\PayException;

/**
 * Class BackPubChargeData
 * @package Payment\Common\Hsq\Data
 */
class BackPubChargeData extends HsqBaseData
{

    public function getData()
    {
        $data = [];
        if(!empty($this->result))
        {
            $result = json_decode($this->result,true);

//         error => Array
//            (
//                [orderStatus] => FAIL
//                [respCode] => 200102
//                [respMsg] => 用户ID不能为空
//            )
//         success => Array
//            (
//                [channelOrderNo] => 23042623411110491231100567786529
//                [orderAmt] => 1
//                [orderStatus] => PROCESSING
//                [payType] => WECHAT_APPLET
//                [qrCode] => {"appId":"wxb63c89abb9243ad0","timeStamp":"1682505329","nonceStr":"9143196887f84ee4a6c62d83f42d844e","package":"prepay_id=wx2618352949503409354c827c2915ab0000","signType":"RSA","paySign":"qDp85A9fHWjLGFpaqmMoRifO9ZHbH6Kfc8X6jxaZ4EKz+OMumFaXMUlAG6tWWl1T6o4dMw35d0O8YvCWseK2V4yXHW0jxcf/0SJ95HD2sPJHtmFeaw7NQGv2jMdAKngewr0pLK9n+EVyNGwfZyCZbg7hzlPK80zD7Sb7/fnaoK0cl5uMwXqOEsE9w1lW4vGUSHEnV/W/R3O/r070ipSYLNG0DXuuisFJIDQexZgV6vbRHs4RyTeOzA7gufWt2ABAGrwcqAVjASdkNx3WPHsNVHCr44YiU6o5C737vn/nqU4d4Clxh+NdK4oFxawbM8McM2UCi0/771hr5w66W35c4A=="}
//                [respCode] => 100201
//                [respMsg] => 交易处理中，请稍后查询
//                [tradeNo] => 25000020230426234103D00000800098
//                [transNo] => WechatPay20230426234103
//            )

            if(!empty($result['qrCode']))
            {
                switch ($result['payType'])
                {
                    case 'WECHAT_APPLET': //微信
                        $qrCode = json_decode($result['qrCode'],true);
                        $data = $qrCode;
                        break;
                    case 'ALI_APPLET': //支付宝
                        $qrCode = $result['qrCode'];
                        $data = $qrCode;
                        break;
                    default:
                }
            }
        }

        $this->retData['package'] = $data;
        $this->retData['other'] = [
            'channelOrderNo' => $result['channelOrderNo'] ?: '',
            'tradeNo' => $result['tradeNo'] ?: '',
            'transNo' => $result['transNo'] ?: '',
        ];

        return parent::getData();
    }


    protected function buildData()
    {
    }

    protected function checkDataParam()
    {
    }

}
